﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebSite_m_data_otherLevel : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null || Session["UserIdentity"].ToString() != "2")
        {
            Response.Redirect("Default.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;
        }

        return;
    }
    protected void InsertBtn_Click(object sender, EventArgs e)
    {
        try
        {
            string TestName = TestNameDropDownList.SelectedItem.Text;
            string High = HighTextBox.Text;
            string Low = LowTextBox.Text;
            string sex = SexDropDownList.SelectedItem.Value;
            string Mark = MarkTextBox.Text;
            string Level = LevelTextBox.Text;
            string HeavyWeight = HeavyWeightTextBox.Text;

            SqlConnection conn = new SqlConnection("Data Source=Localhost;Integrated Security=SSPI;Initial Catalog=CSHDB");
            SqlCommand command = new SqlCommand();
            command.CommandText = "InsertTargetLevel";
            command.Connection = conn;
            conn.Open();
            command.CommandType = CommandType.StoredProcedure;
            SqlParameter[] ArrayParams = {
                                   new SqlParameter("@TestName",TestName),
                                   new SqlParameter("@LowerLimit",float.Parse(Low)),
                                   new SqlParameter("@UpLimit",float.Parse(High)),
                                   new SqlParameter("@Sex",int.Parse(sex)),
                                   new SqlParameter("@Mark",int.Parse(Mark)),
                                   new SqlParameter("@Level",Level),
                                   new SqlParameter("@HeavyWeight",float.Parse(HeavyWeight))
                               };
            foreach (SqlParameter param in ArrayParams)
            {
                command.Parameters.Add(param);
            }
            if(command.ExecuteNonQuery()==1)
            {
                WarnLabel.Text = "成功插入数据";
                WarnLabel.Visible = true;
            }
        }
        catch(Exception ex)
        {
            //跳转到错误处理页面。
            Session["ErrorMessage"] = ex.Message + "\n Source:" + ex.Source + "\n TargetSite: " + ex.TargetSite.ToString() + "\nStackTrace:" + ex.StackTrace;
            Session["AtPage"] = "m_data_otherLevel.aspx";
            Response.Redirect("m_error.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;
        }

    }
}
